#ifndef CONTENTPIPE_H
#define CONTENTPIPE_H

#include <QObject>
#include <QThread>

#include "components/threadid.h"
#include "components/postid.h"
#include "components/board.h"
#include "analyzers/extractor.h"

namespace Wishmaster
{
	class ChanManager;
	class WISHMASTER_EXPORT ContentPipe : public QObject
	{
		Q_OBJECT
	public:
		ContentPipe(ChanManager* manager);

	public slots:
		void contentBoardIndex(const QString& chanName, const QString& boardId, const QByteArray& data);
		void contentThread(const ThreadId& threadId, const QByteArray& data);
		void contentThumbnail(const PostId& postId, int attachmentIndex, const QByteArray& data);
		void contentAttachment(const PostId& postId, int attachmentIndex, const QByteArray& data, const QString& contentType);

	signals:
		void boardUpdated(const QString& chanName, const QString& boardId);
		void threadUpdated(const ThreadId& threadId);
		void postUpdated(const PostId& postId);

	private:
		void processThreadList(Board* board, const QList<ThreadInfo>& threads);
		void processPostList(ThreadPtr& thread, const QList<PostInfo>& posts);
		void addAttachments(const PostInfo& info, PostPtr& post);
		void filterThread(ThreadPtr& thread);

		BoardParser* parserForBoard(const QString& chanName, const QString& boardId);
		void filterThread(ThreadPtr& thread, const FilterListPtr& filterList);
		void extractWatermarks(ThreadPtr& t);

		void requestThumbs(const PostPtr& post);
		void requestAttachments(const PostPtr& post);

		ChanManager* m_manager;
		Extractor m_extractor;
	};
}

#endif // CONTENTPIPE_H
